package com.rd.student.ruanjian.class4.lichunquan.L_2023_7_10;


import java.util.ArrayList;
import java.util.LinkedList;
public class Demo03 {
    public static void main(String[] args) {
        //链表LinkedList
        /*
        前置 prev
        数据 date
        后置 next
        */
        LinkedList_02 linkedList_02 = new LinkedList_02();
        linkedList_02.test01();
    }
}

class LinkedList_02{
    //添加元素
    public void test01(){
        LinkedList linkedList = new LinkedList();
        Student s1 = new Student("李春泉","软件","开心" ,20 ,4);
        Student s2 = new Student("周子贺","软件","开心" , 20,4);
        Student s3 = new Student("高艺铭","软件","开心" , 20,4);
        Student s4 = new Student("王星凯","软件","开心",20 ,4);
        Student s7 = new Student("柏云耀","软件","开心" ,20,4);
        Student s5 = new Student("杜航", "软件","开心" ,20,5);
        Student s6 = new Student("张睿", "软件","开心",20,4);
        linkedList.add(s1);
        linkedList.add(s2);
        linkedList.add(s3);
        linkedList.add(s4);
        linkedList.add(s7);
        linkedList.add(s6);
        linkedList.add(s5);

        Student s = new Student();

        System.out.println(s.studentOfage(linkedList));
        System.out.println("_______");

        System.out.println(s.arrayListAge(linkedList));
        System.out.println("_______");

        System.out.println(s.returnOfclass1(linkedList,4));
        System.out.println("_______");

        System.out.println(s.returnOfzhuanye(linkedList,"软件"));
        System.out.println("_______");

        System.out.println(s.returnOfname(linkedList,"李春泉"));
        System.out.println("_______");

        System.out.println(s.returnOfage(linkedList,20));
        System.out.println("_______");

        System.out.println(s.getSumName(linkedList));

    }
}
class Student{
    private String name;
    private String zhuanye;
    private String miaoshu ;
    private Integer age ;
    private Integer class1;
    private ArrayList arrayList  ;
    private ArrayList arrayListname = new ArrayList();
    private ArrayList arrayListAge = new ArrayList();
    private Student s;
    Student(){}
    public Student(String name, String zhuanye, String miaoshu, Integer age, Integer class1) {
        this.name = name;
        this.zhuanye = zhuanye;
        this.miaoshu = miaoshu;
        this.age = age;
        this.class1 = class1;
    }
    //根据年龄筛选
    public ArrayList studentOfage(LinkedList l){
        for (int i = 0; i < l.size(); i++) {
            s = (Student) l.get(i);
            arrayListAge.add(s);
            if(s.age<=21 && s.age>=20){
            }
        }
        return arrayListAge;
    }
    //平均年龄
    public int arrayListAge(LinkedList l){
        int sum = 0;
        Integer avg = 0;
        Student s ;
        for (int i = 0; i < l.size(); i++) {
            s = (Student) l.get(i);
            avg = s.age;
            sum += avg;
        }
        return sum/l.size();
    }

    //根据班级返回
    public ArrayList returnOfclass1(LinkedList l,Integer class1){
        arrayList =  new ArrayList();
        for (int i = 0; i < l.size(); i++) {
            s=(Student) l.get(i);
            if(s.class1.equals(class1)){
                s = (Student)l.get(i);
                arrayList.add(s);
            }
        }
        return arrayList;
    }
    //根据专业返回
    public ArrayList returnOfzhuanye(LinkedList l,String zhuanye){
        arrayList =  new ArrayList();
        for (int i = 0; i < l.size(); i++) {
            s=(Student) l.get(i);
            if(s.zhuanye.equals(zhuanye)){
                s = (Student)l.get(i);
                arrayList.add(s);
            }
        }
        return arrayList;
    }
    //根据姓名返回
    public Student returnOfname(LinkedList l,String name){
        for (int i = 0; i < l.size(); i++) {
            s=(Student) l.get(i);
            if(s.name.equals(name)){
                s = (Student)l.get(i);
                return s;
            }
        }
        return null;
    }
    //根据年龄返回
    public ArrayList returnOfage(LinkedList l,int age){
        arrayList =  new ArrayList();
        for (int i = 0; i < l.size(); i++) {
            s=(Student) l.get(i);
            if(s.age == (age)){
                s = (Student)l.get(i);
                arrayList.add(s);
            }
        }
        return arrayList;
    }
    //名字集合
    public ArrayList getSumName (LinkedList l){
        String name;
        Student s ;
        for (int i = 0; i < l.size(); i++) {
            s =(Student) l.get(i);
            arrayListname.add(s.name);
        }
        return arrayListname;
    }



    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getZhuanye() {
        return zhuanye;
    }
    public void setZhuanye(String zhuanye) {
        this.zhuanye = zhuanye;
    }
    public int getClass1() {
        return class1;
    }
    public void setClass1(int class1) {
        this.class1 = class1;
    }
    @Override
    public String toString() {
        return "学生：" +
                "姓名：" + name + '\'' +
                ", 专业：" + zhuanye + '\'' +
                ", 班级：" + class1 ;
    }
}


